$(function () {
  $('form').bootstrapValidator({
    message: 'This value is not valid',
    feedbackIcons: {
      valid: 'glyphicon glyphicon-ok',
      invalid: 'glyphicon glyphicon-remove',
      validating: 'glyphicon glyphicon-refresh'
    },
    fields: {
      username: {
        message: '用户名验证失败',
        validators: {
          notEmpty: {
            message: '用户名不能为空'
          },
          stringLength: {
            min: 2,
            max: 6,
            message: '用户名长度必须在2到6位之间'
          },
          callback: {
            message: '用户名不存在'
          }
        }
      },
      password: {
        validators: {
          notEmpty: {
            message: '密码不能为空'
          },
          stringLength: {
            min: 6,
            max: 12,
            message: '用户名长度必须在6到12位之间'
          },
          callback: {
            message: '密码错误'
          }
        }
      }
    }
  });
});

$('form').on("success.form.bv", function(e){
  //阻止表单的默认提交
  e.preventDefault();
  //使用ajax进行提交
  $.ajax({
    url:"/employee/employeeLogin",
    type:"post",
    data:$('form').serialize(),
    dataType:"json",
    success:function(info){
      console.log(info);
      if(info.success === true) {
        location.href = 'index.html';
      }
      if(info.error === 1000) {
        $('form').data("bootstrapValidator").updateStatus("username", "INVALID", "callback");
      }
      if(info.error === 1001) {
        $('form').data("bootstrapValidator").updateStatus("password", "INVALID", "callback")
      }
    }
  });
})

$("[type='reset']").on("click", function(){
  
  //重置表单样式
  $("form").data("bootstrapValidator").resetForm();
  
});